import { observable, action, makeObservable } from "mobx";
import { PageDateSelect } from '@/types/pages/enum'
import { ChangeButton, FnCallBack } from '@/types/header/types'
import { ISaleFull } from "@/types/pages/salesAnalysis/interface";
import { getLineChart, getPieLeftChart,getPieRightChart, getSelesData, getSelesMoney,getMapChinaChart } from "@/api/sale";
import { IStore } from "@/types/pages/base";


/**
 * class Sale
 * 销售分析
 */
class Sale  implements IStore<ISaleFull>  {
    @observable screenData: ISaleFull= {sale:{},saleMoney:{},chinaChart:{},
      pieLeftChart:{},pieRightChart:{},lineChart:{}}

    constructor() {
      makeObservable(this)
  }
     /**
     *
     * @param type 日期选择函数
     * @param date 传入日期
     */
     @action async getScreenData(type: PageDateSelect,date?:Date) {

        // 获取左上部分
        this.screenData.sale= await getSelesData(type,date);
          // 获取左上部分
        this.screenData.saleMoney= await getSelesMoney(type,date);
        this.screenData.pieLeftChart= await getPieLeftChart(type,date);
        this.screenData.pieRightChart= await getPieRightChart(type,date);
        this.screenData.lineChart= await getLineChart(type,date);
        this.screenData.chinaChart= await getMapChinaChart(type,date);
        // this.screenData.sale= await getSelesData();
        // this.screenData.sale= await getSelesData();
        return  this.screenData;
    }

    @action async setLineChartData(type: PageDateSelect,date?:Date) {

      this.screenData.lineChart= await getLineChart(type,date);

      return  this.screenData.lineChart;
  }


}
export default Sale;
